package org.example.Thread01;

public class Dome_Thread04 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("休眠被中断...");
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程已退出...");
        });
        System.out.println("线程是否存活："+t1.isAlive());
        //启动线程
        t1.start();
        Thread.sleep(1000);
        System.out.println("线程是否存活："+t1.isAlive());
        //中断线程
        t1.interrupt();
        //等待线程销毁
        Thread.sleep(100);
        //查看线程是否存活
        System.out.println("线程是否存活："+t1.isAlive());
    }
}
